package com.lmiot.xyclick.Util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MathUtils {
    public static String findFloatNum(String str) {
        Matcher matcher = Pattern.compile("[0-9]+(\\.[0-9]+)?").matcher(str);
        return matcher.find() ? matcher.group(0) : "0";
    }

    public static String findIntNum(String str) {
        Matcher matcher = Pattern.compile("[0-9]+").matcher(str);
        return matcher.find() ? matcher.group(0) : "0";
    }

    public static String findIntNumByDot(String str) {
        Matcher matcher = Pattern.compile("([1-9]\\d*\\.?\\d*)|(0\\.\\d*[1-9])").matcher(str);
        return matcher.find() ? matcher.group(0) : "0";
    }

    public static int parseInt(String str) {
        try {
            return Integer.parseInt(str);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }
}
